n=[[0,0,1,1,0],
   [1,1,0,0,1],
   [0,1,1,0,0],
   [0,0,0,1,0],
   [0,1,0,0,1]]
def find(remote,n,deep):
    if len(remote)==5:
        return remote
    for i in range(deep,len(n)):
        for j in range(len(n[i])):
            if n[i][j]==1 and (j not in remote):
                remote=find(remote+[j],n,deep+1)
                if len(remote)==5:
                    return remote

    return remote[0:-1]

a=(find([],n,0))
for i in a:
    print(i+1)